<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of NewestProducts
 *
 * @author ptu
 */
class NewestProducts extends CWidget {
        public $categoryId;
        
        public function run(){
                $categoryModel=  ProductCategory::model()->findByPk($this->categoryId);
            
                $subIds=  ProductCategory::model()->getAllChildLeafCategoryIds($this->categoryId);
                $criteria=new CDbCriteria();
                $criteria->addInCondition('categoryId', $subIds);
                $criteria->limit=20;
                $criteria->order='create_time desc';
                $listProduct=  Product::model()->findAll($criteria);
                
                $updateTime=date('d/m/Y');
                
                if(isset($listProduct[0])){
                    $updateTime=date('d/m/Y', $listProduct[0]->create_time);
                }
                
                $baseAssetUrl=Yii::app()->getAssetManager()->publish(__DIR__ . DIRECTORY_SEPARATOR . 'assets');
                $cs=Yii::app()->clientScript;
                $cs->registerCssFile($baseAssetUrl . '/newest_product.css');
                
                $this->render('index', array('listProduct'=>$listProduct, 'updateTime'=>$updateTime, 'category'=>$categoryModel));
        }
}

?>
